import TableData from "@/components/public/el-table"; //主页面列表
import TableLyout from '@/components/commonPublic/tableLyoutSpecification.vue'
import tree from "@/components/materialDataManage/specificationManagement/tree"; //左侧机构树
import actions from "@/actions";
import formJs from "./regexDetail.js"; //新增弹框配置

import {
    getSpecificationDataList, //列表页接口

    getSpeciesDataList, //材料种类
} from "@/api/request.js";
import publicForm from "@/components/materialDataManage/fromCom.vue"; //弹框form
export default {
    name: "specificationManagement",
    data() {
        return {
            name: "specificationManagement",
            treelength: false, //左侧树显示隐藏
            treeData: [], //树状数据
            showName: "未选择种类",
            defaultProps: {
                children: "materialList",
                label: "name",
            },
            checkData:[],
            navigatepageNums: null,
            isLock: false,
            projectId: null,
            projectName: null,
            loading: false,
            btnObj: [], //按钮
            queryCriteriaData: {}, //分页
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            radio: "待办",
            // 列表
            getList: {
                page: 1,
                pageSize: 15,
                name: "", //材料种类/名称
                fVersion: "", //规格型号
                fId: "",
            },
            isShow: false, //是否显示弹框

            statusNum: null, //点击那个按钮
            dataFid: null, //列表详情id
            currentRow: null, //列表详情
            activeIndex: "1",
            fId: null, //当前数据fId
            tableData: [],
            companyId: null,
            currentRowId: "",
            dialogTitle: null,
        };
    },
    components: {
        TableLyout,
        publicForm,
        TableData,
        tree,
     
     
    },
    mounted() {
        this.getTree();

    },
    methods: {
        refreshList() { //刷新列表

            this.$nextTick(() => {
                this.yj_searchForm(this.getList);
            })
        },
        closeDialog() {
            this.isShow = false;
        },
        getTree() {
            var obj = {
                page: 1,
                pageSize: 500
            }
            getSpeciesDataList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                      
                        this.treeData = []
                        // var data=[]
                        res.data.pageInfo.list.map(item => {
                            if (item.fStatus == 1) {
                                item.name = item.fVarietyname
                                item.id = item.fVarietyid
                                item.materialList.map(i => {
                                    i.name = i.fMaterialname
                                    i.id = i.fMaterialid
                                })
                                this.treeData.push(item)
                               
                            }
                        })

                        if (this.treeData.length == 0) {
                            this.treelength = false; //左侧组织机构是否显示
                        } else {
                            this.treelength = true;
                            this.checkData[0]=this.treeData[0].id
                            this.getList.fId=this.treeData[0].id
                            this.showName = this.treeData[0].fVarietyname; //当前点击组织机构名称
                        }
                        this.yj_searchForm(this.getList);
                    } else {
                        this.$message.error(res.msg);
                        return false;
                    }
                })
                .catch(() => {
                    return false;
                });
        },
        // 点击左侧机构树
        handleNodeClick(data) {
            this.getList.name=""
            this.showName = data.name; //顶部显示机构名
            this.getList.fId = data.id;
            this.yj_searchForm(this.getList);
        },
        handleRow() {},
  
        getBtnName(name, status) {
            this.statusNum = status
            this.yj_edit(status)
        },

        // 新增/编辑
        yj_edit(num) {
                this.statusNum = num
                this.dialogTitle = "材料规格管理"
               if (num == 7) { //种类材料删除
                    if (this.dataFid != null) {
                        this.editText();
                        this.statusNum = 7
                        this.isShow = true;
                    } else {
                        this.$message.warning("请先选择需要查看的数据");
                    }
                }
          
        },
        editText() {
            this.isShow = true;
        },

 
        // 查看
        // 点击查看
        yj_viewForm(row, label) {
            if (label == "规格型号") {
                this.currentRow = row;
                this.statusNum = 7
                this.dialogTitle = "材料规格管理"

                this.isShow = true;

            }
        },
        // 点击当前行变色
        rowChange(val) {
            this.currentRow = val
            this.dataFid = val.fId;
        },
        // 获取列表数据
        yj_searchForm(data) {
            var obj = {
                page: data.page,
                pageSize: data.pageSize,
                name: data.name, //材料种类/名称
                fVersion: data.fVersion, //规格型号
                fId: data.fId
            }
            this.loading = true;
            var that = this;
            getSpecificationDataList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        this.queryCriteriaData = res.data.pageInfo;
                    } else {
                        this.$message.error("列表数据获取失败", res.msg);
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error("列表数据 接口出错", error.msg);
                    this.loading = false;
                });
        },
    },
};